<?php
if (!function_exists('substr_cut')) {
    function substr_cut($str, $length=5, $begin=0) { 
        $i = $begin;
        $result=""; 
        while($length > 0){
            if(ord($str[$i]) > 127) {
                $result .= substr($str,$i,3);  
                $i = $i+3;  
            }else{
                $result .= substr($str,$i,1);  
                $i++;  
            }
            $length--;
        }  
        return $result."...";
    } 
}

if (!function_exists('refeshSession')) {
    function refreshSession($key, $content) {
        Illuminate\Support\Facades\Session::put($key, $content);
        Illuminate\Support\Facades\Session::save();
    }
}

if (!function_exists('sendSMS')) {
    function sendSMS($username,$password,$mobile,$content,$apikey) {
        $url = config("global.site.msg.url");
        $post_fields = array(
            'username'=>$username,
            'password'=>$password,
            'mobile'=>$mobile,
            'content'=>$content,
            'apikey'=>$apikey,
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 3600); //60秒 
        curl_setopt($ch, CURLOPT_HEADER,1);
        curl_setopt($ch, CURLOPT_REFERER,  config("global.site.msg.mydomain"));
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$post_fields);
        $data = curl_exec($ch);
        curl_close($ch);
        $res = explode("\r\n\r\n",$data);
        return $res[2];
    }
}
